import requests
import hashlib
import json

# 登录
username = 'yh'
password = '123456'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用方法hexdigest()加密
# 构造请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'Content-Type': 'application/json;charset=UTF-8'
}
# # 构建url
url_base = r'http://192.168.232.128:3000'
url_login = url_base + r'/jshERP-boot/user/login'
# 构建data
data_login = {"loginName": username, "password": password_md5}
# 发送请求
resp = requests.post(url_login, json=data_login, headers=headers)
# 获取响应
token = resp.json()['data']['token']
print(token)

# ----------------------角色管理：新增----------------------
# name = 'test01'
# type = '全部数据'
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造 url
# url_role_add = url_base + r'/jshERP-boot/role/add'
# # 构造 data
# data_role_add = {"name": name, "type": type}
# # 发送请求
# resp = requests.post(url_role_add, json=data_role_add, headers=headers, verify=False)
# # 获取响应
# message = resp.json()['data']['message']
# print(message)

# ----------------------角色管理：修改----------------------
# name = 'test01'
# type = '全部数据'
# id = 28
# # {"deleteFlag":"0","enabled":true,"id":28,"name":"test001","tenantId":136,"type":"全部数据"}
# #
# # 构造url
# url_role_mod = url_base + r'/jshERP-boot/role/update'
# # 构造data
# data_role_mod = {"deleteFlag": "0", "enabled": True, "id": id, "name": name, "tenantId": 136,
#                  "type": type}
# # 发送请求
# resp = requests.put(url_role_mod, headers=headers, json=data_role_mod)
# # 获取响应
# print(resp.text)

# ----------------------角色管理：查询----------------------
# name = 'test01'
# description = ''
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url
# url_role_query = url_base + r'/jshERP-boot/role/list'
# # 构造data
# search_dict = {"name": name, "description": description}
# search_str = json.dumps(search_dict)
# data_role_query = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
# # 发送请求
# resp = requests.get(url_role_query, params=data_role_query, headers=headers)
# # 获取响应
# print(resp.text)

# ----------------------角色管理：删除----------------------
# id = 36
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url
# url_role_del = url_base + r'/jshERP-boot/role/delete'
# # 构造data
# data_role_del = {'id': id}
# # 发送请求
# resp = requests.delete(url_role_del, headers=headers, params=data_role_del)
# # 获取响应
# print(resp.text)

# ----------------------零售出库管理：新增----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/addDepotHeadAndDetail
# url_retail_add = url_base + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# # 构造data
# number = 'LSCK00000000859'
# payType = '现付'
# info_dict = {"organId": 85, "operTime": "2024-01-12 11:39:36", "number": number, "payType": payType,
#              "changeAmount": "100.00", "getAmount": "100.00", "backAmount": 0, "accountId": 21, "type": "出库",
#              "subType": "零售", "defaultNumber": number, "totalPrice": 100, "fileName": "",
#              "status": "0"}
# info_str = json.dumps(info_dict)
# data_retail_add = {
#     "info": info_str,
#     "rows": "[{\"id\":\"17050307767160292492\",\"name\":\"电脑\",\"standard\":\"8g\",\"model\":null,\"color\":\"黑\","
#             "\"materialOther\":\"\",\"stock\":90,\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\","
#             "\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"1\",\"unitPrice\":100,\"allPrice\":100,"
#             "\"remark\":\"\",\"orderNum\":1,\"depotId\":\"20\",\"barCode\":\"1001\"}]"
# }
# # 发送请求
# resp = requests.post(url_retail_add, headers=headers, json=data_retail_add)
# # 获取响应
# print(resp.text)

# ----------------------零售出库管理：修改----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/updateDepotHeadAndDetail
# url_retail_mod = url_base + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# # 构造data
# organName = '电脑会员'
# payType = '现付'
# info_dict = {"id": 12279, "type": "出库", "subType": "零售", "defaultNumber": "LSCK00000000815",
#              "number": "LSCK00000000815", "createTime": "2024-01-12T03:40:26.000+0000",
#              "operTime": "2024-01-12 11:39:36", "organId": 86, "creator": 136, "accountId": 22, "changeAmount": 700,
#              "backAmount": 0, "totalPrice": 700, "payType": payType, "billType": "", "remark": "", "fileName": "",
#              "salesMan": "", "accountIdList": "", "accountMoneyList": "", "discount": "", "discountMoney": "",
#              "discountLastMoney": 0, "otherMoney": "", "deposit": 0, "status": "0", "purchaseStatus": "0",
#              "source": "0", "linkNumber": "", "tenantId": 136, "deleteFlag": "0", "projectName": "",
#              "organName": "键盘会员", "userName": "", "accountName": organName, "allocationProjectName": "",
#              "materialsList": "电脑 8g ", "salesManStr": "", "operTimeStr": "2024-01-12 11:39:36", "finishDebt": "",
#              "depotHeadType": "零售出库", "creatorName": "yh", "contacts": "", "telephone": "", "address": "",
#              "finishDeposit": "", "needDebt": "", "debt": -700, "materialCount": "", "hasFinancialFlag": False,
#              "hasBackFlag": False, "realNeedDebt": "", "getAmount": 700}
#
# info_str = json.dumps(info_dict)
# data_retail_mod = {
#     "info": info_str,
#     "rows": "[{\"id\":\"16589\",\"name\":\"电脑\",\"standard\":\"8g\",\"model\":\"\",\"color\":\"黑\",\"materialOther\":\"\",\"stock\":\"77\",\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"7\",\"unitPrice\":\"100\",\"allPrice\":700,\"remark\":\"\",\"orderNum\":1,\"depotId\":\"20\",\"barCode\":\"1001\"}]"
# }
# # 发送请求
# resp = requests.put(url_retail_mod, headers=headers, json=data_retail_mod)
# # 获取响应
# print(resp.text)

# ----------------------零售出库管理：查询----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/list
# url_retail_search = url_base + r'/jshERP-boot/depotHead/list'
# # 构造data
# number = 'LSCK00000000820'
# materialParam = ''
# search_dict = {"number": number, "materialParam": materialParam, "type": "出库", "subType": "零售",
#                "roleType": "全部数据", "organId": "", "depotId": "", "creator": "", "accountId": "", "status": "",
#                "remark": ""}
# search_str = json.dumps(search_dict)
# data_retail_search = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
# # 发送请求
# reso = requests.get(url_retail_search, params=data_retail_search, headers=headers)
# # 获取响应
# print(resp.text)

# ----------------------零售出库管理：删除----------------------
# id = 12281
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url
# url_retail_del = url_base + r'/jshERP-boot/depotHead/delete'
# # 构造data
# data_retail_del = {'id': id}
# # 发送请求
# resp = requests.delete(url_retail_del, headers=headers, params=data_retail_del)
# # 获取响应
# print(resp.text)


# ----------------------零售退货管理：新增----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/addDepotHeadAndDetail
# url_retail_back_add = url_base + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# # 构造data
# number = 'LSCK00000000888'
# info_dict = {"organId": 85, "operTime": "2024-01-12 16:02:24", "number": number, "changeAmount": -100,
#              "getAmount": "100.00", "backAmount": 0, "accountId": 21, "type": "入库", "subType": "零售退货",
#              "defaultNumber": number, "totalPrice": -100, "fileName": "", "status": "0"}
# info_str = json.dumps(info_dict)
# data_retail_back_add = {
#     "info": info_str,
#     "rows": "[{\"id\":\"17050465440520509471\",\"name\":\"键盘\",\"standard\":\"86\",\"model\":null,\"color\":null,"
#             "\"materialOther\":\"\",\"stock\":19,\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\","
#             "\"expirationDate\":\"\",\"sku\":\"\",\"preNumber\":\"\",\"finishNumber\":\"\",\"operNumber\":\"5\","
#             "\"unitPrice\":20,\"allPrice\":100,\"remark\":\"\",\"linkId\":\"\",\"orderNum\":1,\"depotId\":\"20\","
#             "\"barCode\":\"1002\"}]"
# }
# # 发送请求
# resp = requests.post(url_retail_back_add, headers=headers, json=data_retail_back_add)
# # 获取响应
# print(resp.text)

# ----------------------零售退货管理：修改----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/updateDepotHeadAndDetail
# url_retail_back_mod = url_base + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# # 构造data
# organName = '电脑会员'
# info_dict = {"id": 12286, "type": "入库", "subType": "零售退货", "defaultNumber": "LSCK00000000888",
#              "number": "LSCK00000000888", "createTime": "2024-01-12T08:11:03.000+0000",
#              "operTime": "2024-01-12 16:02:24", "organId": 86, "creator": 136, "accountId": 22, "changeAmount": -100,
#              "backAmount": 0, "totalPrice": -100, "payType": "现付", "billType": "", "remark": "", "fileName": "",
#              "salesMan": "", "accountIdList": "", "accountMoneyList": "", "discount": "", "discountMoney": "",
#              "discountLastMoney": 0, "otherMoney": "", "deposit": 0, "status": "0", "purchaseStatus": "0",
#              "source": "0", "linkNumber": "", "tenantId": 136, "deleteFlag": "0", "projectName": "",
#              "organName": organName, "userName": "", "accountName": "电脑账户", "allocationProjectName": "",
#              "materialsList": "键盘 86 ", "salesManStr": "", "operTimeStr": "2024-01-12 16:02:24", "finishDebt": "",
#              "depotHeadType": "零售退货入库", "creatorName": "yh", "contacts": "", "telephone": "", "address": "",
#              "finishDeposit": "", "needDebt": "", "debt": -100, "materialCount": "", "hasFinancialFlag": False,
#              "hasBackFlag": False, "realNeedDebt": "", "getAmount": 100}
#
# info_str = json.dumps(info_dict)
# data_retail_back_mod = {
#     "info": info_str,
#     "rows": "[{\"id\":\"16589\",\"name\":\"电脑\",\"standard\":\"8g\",\"model\":\"\",\"color\":\"黑\",\"materialOther\":\"\",\"stock\":\"77\",\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"7\",\"unitPrice\":\"100\",\"allPrice\":700,\"remark\":\"\",\"orderNum\":1,\"depotId\":\"20\",\"barCode\":\"1001\"}]"
# }
# # 发送请求
# resp = requests.put(url_retail_back_mod, headers=headers, json=data_retail_back_mod)
# # 获取响应
# print(resp.text)

# ----------------------零售退货管理：查询----------------------
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url:/jshERP-boot/depotHead/list
# url_retail_search = url_base + r'/jshERP-boot/depotHead/list'
# # 构造data
# number = 'LSTH00000000820'
# materialParam = ''
# search_dict = {"number": number, "materialParam": materialParam, "type": "出库", "subType": "零售",
#                "roleType": "全部数据", "organId": "", "depotId": "", "creator": "", "accountId": "", "status": "",
#                "remark": ""}
# search_str = json.dumps(search_dict)
# data_retail_search = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
# # 发送请求
# reso = requests.get(url_retail_search, params=data_retail_search, headers=headers)
# # 获取响应
# print(resp.text)

# ----------------------零售退货管理：删除----------------------
# id = 12286
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造url
# url_retail_del = url_base + r'/jshERP-boot/depotHead/delete'
# # 构造data
# data_retail_del = {'id': id}
# # 发送请求
# resp = requests.delete(url_retail_del, headers=headers, params=data_retail_del)
# # 获取响应
# print(resp.text)
